package projectsys.sys.core.utils;

import java.util.Iterator;
import java.util.List;
import java.util.Properties;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.ConfigurationFactory;
import org.apache.log4j.Logger;

public final class ConfigUtil {

	private static final String CONFIG_FILE_NAME = "config.xml";

	private static Logger logger = Logger.getLogger(ConfigUtil.class);

	private static Configuration config = null;

	static {
		try {
			config = new ConfigurationFactory(CONFIG_FILE_NAME)
					.getConfiguration();
		} catch (ConfigurationException e) {
			logger.error("读取" + CONFIG_FILE_NAME + "文件错误!", e);
		}
	}

	private ConfigUtil() {
	}

	public static String getString(String key) {
		return config.getString(key);
	}

	public static int getInt(String key) {
		return config.getInt(key);
	}

	public static boolean getBoolean(String key) {
		return config.getBoolean(key);
	}

	public static double getDouble(String key) {
		return config.getDouble(key);
	}

	public static float getFloat(String key) {
		return config.getFloat(key);
	}

	public static short getShort(String key) {
		return config.getShort(key);
	}

	public static long getLong(String key) {
		return config.getLong(key);
	}

	public static String[] getStringArray(String key) {
		return config.getStringArray(key);
	}

	public static List<?> getList(String key) {
		return config.getList(key);
	}

	public static Iterator<?> getKeys() {
		return config.getKeys();
	}

	public static boolean isEmpty() {
		return config.isEmpty();
	}

	public static boolean containsKey(String key) {
		return config.containsKey(key);
	}

	public static void clear() {
		config.clear();
	}

	public static void addProperty(String key, String value) {
		config.addProperty(key, value);
	}

	public static void setProperty(String key, String value) {
		config.setProperty(key, value);
	}

	public static Object getProperty(String key) {
		return config.getProperty(key);
	}

	public static Properties getProperties(String key) {
		return config.getProperties(key);
	}

	public static void clearProperty(String key) {
		config.clearProperty(key);
	}
}
